package codetop.dfs;

import java.util.Queue;
import java.util.Stack;

public class Code98 {
    public boolean isValidBST(TreeNode root) {
        Stack<TreeNode>stack=new Stack<>();
        Long max=Long.MIN_VALUE;
        while (!stack.isEmpty()||root!=null){
            while (root!=null){
                stack.push(root);
                root=root.left;
            }
            root=stack.pop();
            if (root.val<=max)return false;
            //max= root.val;
            root=root.right;
        }
        return true;
    }
}
